<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<meta http-equiv="Pragma" content="no-cache"> 
<meta http-equiv="Cache-Control" content="no-cache"> 
<meta http-equiv="Expires" content="0"> 
<title>源辰信息-后台管理</title>
<link rel="shortcut icon" type="image/x-icon" href="images/yc.png"/>
<link href="css/login.css" type="text/css" rel="stylesheet"> 
<style type="text/css">
	#yzm{
		width: 300px;
		position: relative;
		top: -15px;
	}
</style>
</head> 
<body> 

<div class="login">
    <div class="message">零食网-用户登录</div>
    <div id="darkbannerwrap"></div>
    <form id="myform">
    	<select name="role" id="role">
    		<option value="0">超级管理员</option>
    		<option value="1">普通管理员</option>
    	</select>
		<hr class="hr15">
		<input name="username" id="username" placeholder="账号" required type="text" value="navy">
		<hr class="hr15">
		<input name="password" id="pwd" placeholder="密码" required type="password" value="123321">
		<hr class="hr15">
		
		<input name="password" id="yzm" placeholder="验证码" required type="text">
		<!-- 验证码图片 防止图片缓存 加一个时间 保证是一个新的请求 -->
		<img src="../code" onclick="this.src='../code?d=' + new Date()">
		<hr class="hr15">
		
		<span id="waring-info" style="color:red"></span>
		<hr class="hr15">
		<input value="登录" style="width:100%;" type="button" onclick="userLogin()">
		<hr class="hr20">
	</form>
	<div id="adminOp">
		<a href="pwd.html">忘记密码</a>
		<a href="reg.html">注册账号</a>
	</div>
</div>

<div class="copyright">衡阳市源辰信息科技有限公司 &copy; <a href="http://www.hyycinfo.com" target="_blank">后台管理系统</a></div>

<script type="text/javascript" src="../js/jquery-3.4.1.min.js"></script>
<!-- <script type="text/javascript" src="../js/vue.js"></script>
<script type="text/javascript" src="../js/axios.js"></script>
<script type="text/javascript" src="../js/qs.js"></script> -->

<script type="text/javascript">
function userLogin(){
	// 获取界面参数
	let role = $("#role").val().trim();
	let aname = $("#username").val().trim();
	let pwd = $("#pwd").val().trim();
	let yzm = $("#yzm").val().trim();
	
	// TODO 正则表达式验证
	
	// 发送登录业务请求
	$.post('../admin/login', {aname, pwd, role, yzm}, data=>{
		if (data == 200){// 登录成功
			location.href = "manager/index.html";
			return;
		}
		
		if (data == 504){  // 登录成功
			$("#waring-info").html("验证码不匹配！")
			return;
		}
		$("#waring-info").html("登录失败！")
	})
	 
	 // TODO 本地存储 localStorage
	// location.href = "manager/index.html";
}

</script>	
</body>
</html>